package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bean.DeptBean;
import com.project.bean.EmployeeBean;
import com.project.mapper.IDeptMapper;
import com.project.mapper.IEmployeeMapper;
import com.project.service.IDeptService;
import com.project.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class DeptServiceImpl implements IDeptService {
    @Autowired
    private IDeptMapper deptMapper ;
    @Autowired
    private IEmployeeMapper emMapper;
    @Override
    public List<DeptBean> findAll() {
        return deptMapper.findAll();
    }

    @Override
    public void add(DeptBean dept, List<EmployeeBean> emList) {
         deptMapper.insert(dept);
        emMapper.addMore(dept.getId(),emList);
    }

    @Override
    public void delCasede(Integer id) {
        deptMapper.delCasede(id);
    }

    @Override
    public void delSetNull(Integer id) {
        deptMapper.delSetNull(id);
    }

    @Override
    public DeptBean findById(Integer id) {
        DeptBean deptBean = deptMapper.selectById(id);
        QueryWrapper<EmployeeBean>qw = new QueryWrapper<>();
        qw.eq("fk_deptId",id);
        deptBean.setEmList(emMapper.selectList(qw));
        return deptBean;
    }
}
